#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>

int prime(int number) {
	int i;
	for (i = 2; i < sqrt(number) + 1; i++) {
		if (number % i == 0) {
			return 1;
		}
	}
	return 0;
}

int main(int argc, char ** argv) {
	char * fifo_path = argv[1];
	FILE * fifo = fopen(fifo_path, "r");
	int number;
	if (fifo == NULL) {
		perror(fifo_path);
		return -1;
	}
	printf("Liczby pierwsze z kolejki fifo:\n");
	while (fscanf(fifo, "%d\n", &number) >= 0) {
		if (prime(number) == 0) {
			printf("%d\n", number);
		}
	}
	fclose(fifo);
	return 0;
}
